home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 2 / Atari Mega Archive CD - Volume 2.iso / linux / src / atalnx_3.lzh / atari-linux-0.01pl3 / atari / stdma.c < prev   
Encoding:
C/C++ Source or Header  |  1994-06-10  |  3.6 KB  |  162 lines

  1.  
  2. /*
  3.  *  linux/atari/stmda.c
  4.  *
  5.  *  Copyright (C) 1994 Roman Hodek
  6.  *
  7.  *
  8.  * This file is subject to the terms and conditions of the GNU General Public
  9.  * License.  See the file README.legal in the main directory of this archive
  10.  * for more details.
  11.  */
  12.  
  13.  
  14. /* This file contains some function for controlling the access to the  */
  15. /* ST-DMA chip that may be shared between devices. Currently we have:  */
  16. /*   TT:     Floppy and ACSI bus                                       */
  17. /*   Falcon: Floppy, SCSI and IDE                                      */
  18. /*                                                                     */
  19. /* The controlling functions set up a wait queue for access to the     */
  20. /* ST-DMA chip. Callers to stdma_lock() that cannot granted access are */
  21. /* put onto a queue and waked up later if the owner calls              */
  22. /* stdma_release(). Additionally, the caller gives his interrupt       */
  23. /* service routine to stdma_lock().                                    */
  24.  
  25. #include <linux/types.h>
  26. #include <linux/sched.h>
  27. #include <linux/atari_stdma.h>
  28. #include <linux/atariints.h>
  29. #include <linux/atarihw.h>
  30.  
  31.  
  32. static int        stdma_locked = 0;                /* the semaphore */
  33. static isrfunc    stdma_isr = NULL;                /* int func to be called */
  34. static void        *stdma_isr_data = NULL;            /* data passed to isr */
  35. static struct wait_queue    *stdma_wait = NULL;    /* wait queue for ST-DMA */
  36.  
  37.  
  38.  
  39.  
  40. /***************************** Prototypes *****************************/
  41.  
  42. static void stdma_int( struct intframe *fp, void *data );
  43.  
  44. /************************* End of Prototypes **************************/
  45.  
  46.  
  47.  
  48. /*
  49.  * Function: void stdma_lock( isrfunc isr, void *data )
  50.  *
  51.  * Purpose: Trys to get a lock on the ST-DMA chip that is used by more
  52.  *   then one device driver. Waits on stdma_wait until lock is free.
  53.  *   stdma_lock() may not be called from an interrupt! You have to
  54.  *   get the lock in your main routine and release it when your
  55.  *   request is finished.
  56.  *
  57.  * Inputs: A interupt function that is called until the lock is
  58.  *   released.
  59.  *
  60.  * Returns: nothing
  61.  *
  62.  */
  63.  
  64. void stdma_lock( isrfunc isr, void *data )
  65.    
  66. {    unsigned long    oldflags;
  67.  
  68.     save_flags(oldflags);
  69.     cli();        /* protect lock */
  70.  
  71.     while( stdma_locked )
  72.         /* Since the DMA is used for file system purposes, we have to sleep */
  73.         /* uninterruptible (there may be locked buffers) */
  74.         sleep_on( &stdma_wait );
  75.  
  76.     stdma_locked   = 1;
  77.     stdma_isr      = isr;
  78.     stdma_isr_data = data;
  79.     restore_flags(oldflags);
  80. }
  81.  
  82.  
  83. /*
  84.  * Function: void stdma_release( void )
  85.  *
  86.  * Purpose: Releases the lock on the ST-DMA chip. 
  87.  *
  88.  * Inputs: none
  89.  *
  90.  * Returns: nothing
  91.  *
  92.  */
  93.  
  94. void stdma_release( void )
  95.  
  96. {    unsigned long    oldflags;
  97.  
  98.     save_flags(oldflags);
  99.     cli();
  100.     
  101.     stdma_locked = 0;
  102.     wake_up( &stdma_wait );
  103.  
  104.     restore_flags(oldflags);
  105. }
  106.  
  107.  
  108. /*
  109.  * Function: int stdma_others_waiting( void )
  110.  *
  111.  * Purpose: Check if someone waits for the ST-DMA lock.
  112.  *
  113.  * Inputs: none
  114.  *
  115.  * Returns: 0 if noone is waiting, != 0 otherwise
  116.  *
  117.  */
  118.  
  119. int stdma_others_waiting( void )
  120.  
  121. {
  122.     return( stdma_wait != NULL );
  123. }
  124.  
  125.  
  126. /*
  127.  * Function: void stdma_init( void )
  128.  *
  129.  * Purpose: Initialize the ST-DMA chip access controlling.
  130.  *   It sets up the interrupt and its service routine.
  131.  *
  132.  * Inputs: none
  133.  *
  134.  * Return: nothing
  135.  *
  136.  */
  137.  
  138. void stdma_init( void )
  139.  
  140. {
  141.     stdma_isr = NULL;
  142.     add_isr( IRQ_MFP_FDC, stdma_int, 0, NULL );
  143.     mfp.int_en_b |= 0x80;    /* enable int */
  144.     mfp.int_mk_b |= 0x80;    /* not masked */
  145. }
  146.  
  147.  
  148. /*
  149.  * Function: void stdma_int()
  150.  *
  151.  * Purpose: The interupt routine for the ST-DMA. It calls the isr
  152.  *   registered by stdma_lock().
  153.  *
  154.  */
  155.  
  156. static void stdma_int( struct intframe *fp, void *data )
  157.  
  158. {
  159.     if (stdma_isr)
  160.         (*stdma_isr)( fp, stdma_isr_data );
  161. }
  162.